package com.bee.剑指offer;

import java.util.Stack;

/**
 * @version 1.0.0
 * @Author yong.Mr
 * @data 2021-04-18
 */
public class 包含min函数的栈 {

    // 正常存储数据的栈
    Stack<Integer> stack1 = new Stack<Integer>();
    // 辅助栈
    Stack<Integer> stack2 = new Stack<Integer>();

    public void push(int node) {
        stack1.push(node);
        if(stack2.empty()){
            stack2.push(node);
        } else {
            if(node < stack2.peek()) {
                stack2.push(node);
            } else {
                stack2.push(stack2.peek());
            }
        }
    }

    public void pop() {
        if(!stack1.empty()){
            stack1.pop();
        }
        if(!stack2.empty()) {
            stack2.pop();
        }
    }

    public int top() {
        return stack1.peek();
    }

    public int min() {
        return stack2.peek();
    }

    public static void main(String[] args) {

    }
}
